#!/usr/bin/env bash

requirements_smartos_lib_installed()
{
  pkgin list | __rvm_grep "^$1-[0-9]" >/dev/null 2>&1|| return $?
}

requirements_smartos_lib_available()
{
  pkgin avail | __rvm_grep "^$1-[0-9]" >/dev/null 2>&1|| return $?
}

requirements_smartos_libs_install()
{
  __rvm_try_sudo pkgin -y install "$@" || return $?
}

requirements_smartos_update_system()
{
  __rvm_try_sudo pkgin -y full-upgrade || return $?
}

requirements_smartos_define()
{
  case "$1" in
    (rvm)
      requirements_check bash curl patch git
      ;;

    (jruby*)
      requirements_check make openjdk7

      if
        is_head_or_disable_binary "$1"
      then
        requirements_check git
        case $( jruby_installation_method  "$1" ) in
          ant) requirements_check apache-ant   ;;
          mvn) requirements_check apache-maven ;;
        esac
      fi
      ;;

    (ir*)
      requirements_check mono
      ;;

    (opal)
      requirements_check nodejs
      ;;

    (*-head)
      requirements_check coreutils gcc47 gmake readline sqlite3 ncurses libyaml autoconf automake libtool libxslt
      __rvm_update_configure_opt_dir "$1" "/opt/local"
      ;;

    (*)
      requirements_check coreutils gcc47 gmake readline sqlite3 ncurses libyaml autoconf automake libtool libxslt
      __rvm_update_configure_opt_dir "$1" "/opt/local"
      ;;
  esac
}
